#!/usr/bin/env python
# -*- coding: utf-8 -*-

import xlrd
import xlwt
import os

class ExcelControl():

    def __init__(self,excel_path):
        self.sheet_name = 'Sheet1'
        self.col_name = 'URL'
        self.excel_path = excel_path

    def get_exce_data(self):
        data = xlrd.open_workbook(self.excel_path)
        table = data.sheet_by_name(self.sheet_name)
        banner = table.row_values(0)
        for i in range(1,table.nrows):
            yield zip(banner,table.row_values(i))

    def __handle_data(self, datas):
        print("11")
        for item in datas:
            _, url_datas = item
            url_datas = list(url_datas)
            if not len(url_datas) == 2:
                continue
            for url_data in url_datas:
                yield (url_data['URL'],str(url_data['HEADER']),str(url_data['BODY']),str(url_data['RESPONSE']))
        
    def _save_date(self, save_path, new_table_data):
        myWorkbook = xlwt.Workbook()
        mySheet = myWorkbook.add_sheet(self.sheet_name)
        x,y = 0,0
        for i in self.__handle_data(new_table_data):
            print(i)
            for j in i:
                print(j)
                mySheet.write(x,y,j)
                y += 1
            y = 0
            x += 1
        myWorkbook.save(save_path)

'''
if __name__ == '__main__':
    ec = ExcelControl('CASE.xls')
    for item in ec.get_exce_data():
        print(dict(item))
'''